import java.util.Arrays;
import java.util.Random;

public class Main {
    public static void initOrder(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }

    public static void notOrder(int[] array){
        Random random =new Random();
        for(int i=0;i<array.length;i++){
            array[i]=random.nextInt(100000);
        }
    }

    public static void testInsert(int[] array){
        int[] tmpArray= Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.insertSort(tmpArray);
        long endTime=System.currentTimeMillis();
        System.out.println("直接插入排序耗时："+(endTime-startTime));
    }

    public static void testShell(int[] array){
        int[] tmpArray= Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.shellSort(tmpArray);
        long endTime=System.currentTimeMillis();
        System.out.println("希尔排序耗时："+(endTime-startTime));
    }

    public static void testSelect(int[] array){
        int[] tmpArray= Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.selectSort(tmpArray);
        long endTime=System.currentTimeMillis();
        System.out.println("选择排序耗时："+(endTime-startTime));
    }

    public static void testHeap(int[] array){
        int[] tmpArray= Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.heapSort(tmpArray);
        long endTime=System.currentTimeMillis();
        System.out.println("堆排序耗时："+(endTime-startTime));
    }

    public static void testBubble(int[] array){
        int[] tmpArray= Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.bubbleSort(tmpArray);
        long endTime=System.currentTimeMillis();
        System.out.println("冒泡序耗时："+(endTime-startTime));
    }

    public static void testQuik(int[] array){
        int[] tmpArray= Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.quickSort(tmpArray);
        long endTime=System.currentTimeMillis();
        System.out.println("快速排序耗时："+(endTime-startTime));
    }

    public static void testMerge(int[] array){
        int[] tmpArray= Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.mergeSort(tmpArray);
        long endTime=System.currentTimeMillis();
        System.out.println("归并排序耗时："+(endTime-startTime));
    }

   public static void main(String[] args){
       int array[] =new int[100000];
       /*initOrder(array);*/
       notOrder(array);
       testInsert(array);
       testShell(array);
       testSelect(array);
       testHeap(array);
       testBubble(array);
       testQuik(array);
       testMerge(array);
   }

}
